package com.gxufl.console;

import java.util.List;
import java.util.Scanner;

import com.gxufl.Application;
import com.gxufl.entity.Notice;
import com.gxufl.service.NoticeService;

public class NoticeConsole {
	NoticeService service = new NoticeService();

	public void searchNotice() {
		NoticeService service = new NoticeService();
		List<Notice> list = service.searchNotice();
		// for打印输出
		for (int i = 0, ii = list.size(); i < ii; i++) {
			Notice notice = list.get(i);
			System.out.println(String.format("%d、%s 上映《%s》", (i+1),notice.showdate, notice.name)+"\n");
			
		}
		Application.fn显示主菜单();
	}
	
	//保存海报逻辑
	public void saveNotice(){
		Scanner sc=new Scanner(System.in);
		System.out.println("请输入电影名称");
		String name=sc.next();
		System.out.println("请输入电影介绍");
		String content=sc.next();
		System.out.println("请输入电影上映日期");
		String showdate=sc.next();
		System.out.println("请输入电影优先级");
		Integer priority=sc.nextInt();
		
		Notice notice=new Notice(name,content,showdate,priority);		
		service.saveNotice(notice);
	}
	
	//删除海报逻辑
	public void deleteNotice(){
		Scanner sc=new Scanner(System.in);
		System.out.println("请输要删除的电影");
		String name=sc.next();
				
		service.deleteNotice(name);
	}
	
	
	public void updateNotice(){
		//要求需要更新的电影名称
		Scanner sc=new Scanner(System.in);
		System.out.println("请输入要更新的电影名称");
		String name=sc.next();
		//根据电影名称查出电影实体
		List<Notice> list = service.searchNotice(name,null);
		//验证list的数量，如果不为1，那么给出错误提示
		
		
		//修改实体对应的属性
		Notice notice=list.get(0);
		System.out.println("请输入电影《"+notice.name+"》简介");
		String content=sc.next();
		notice.content = content;
		
		// 4、对修改后的实体进行保存
		
		service.saveNotice(notice);
	}
}
